<?php $this->load->view('head'); ?>
<script type="text/javascript" src="<?php echo get_static_url();?>admin/js/tag.js"></script>
<div class="main clear">
    <form  id="article_form" method="post" action="index.php?d=admin&c=news&m=cmd_save" onsubmit="return check();">
            <div class="add_item" style="margin-top: 10px;">
                <label>文章标题：</label>
                <input type="text" value="<?php if(isset($data) && $data['title']){echo $data['title'];}?>" id="title" name="title" class="txt width500">
            </div>
            <div class="add_item">
                <label>短标题：</label>
                <input type="text" value="<?php if(isset($data) && $data['shorttitle']){echo $data['shorttitle'];}?>" id="shorttitle" name="shorttitle" class="txt width500">
            </div>
            <div class="add_item">
                    <label>自定义属性：</label>
                    <div class="add_cbox" style="width: 600px;">
                            <input type="checkbox" value="c" name="flag[]" class="checkbox" <?php if(isset($data) && strpos($data['flag'],'c') !== false){?> checked="checked" <?php }?>>
                            <span>推荐</span>
                            <input type="checkbox" value="f" name="flag[]" class="checkbox" <?php if(isset($data) && strpos($data['flag'],'f') !== false){?> checked="checked" <?php }?>>
                            <span>幻灯</span>
                            <input type="checkbox" value="w" name="flag[]" class="checkbox" <?php if(isset($data) && strpos($data['flag'],'w') !== false){?> checked="checked" <?php }?>>
                            <span>wap页推荐</span>
                    </div>
            </div>
            <div class="add_item">
                <label>列表页缩略图：</label>
                <select id="islist" name="islist" class="txt">
                    <option value="0" <?php if(isset($data) && !$data['listlitimg']){?> selected="selected" <?php }?>  >否</option>
                    <option value="1" <?php if(isset($data) && $data['listlitimg']){?>  selected="selected"  <?php }?> >是</option>
                </select>
            </div>
                        
            <div <?php if(!isset($data) || $data['listlitimg'] == ''){?> style="display:none;"   <?php }?> id="div_islist" class="add_item">
                    <label>图片：</label>
                    <input type="text" value="<?php if(isset($data)){echo $data['listlitimg'];}?>" id="islist_pic" name="listpic" class="txt width500">
                    <a onclick="showupwindow('islist_pic')" href="javascript:;">上传</a>
                    <span style="color: silver;">大小：<b>493*260</b></span>
            </div>
            <div class="add_item">
                <label>列表页幻灯：</label>
                <select id="isfirstSlideShow" name="isfirstSlideShow" class="txt">
                    <option value="0" <?php if(isset($data) && !$data['first_slide']){?> selected="selected" <?php }?>>否</option>
                    <option value="1" <?php if(isset($data) && $data['first_slide']){?> selected="selected" <?php }?>>是</option>
                </select>
            </div>
            <div class="add_item">
                <label>列表页图推：</label>
                <select id="isColumnreCommend" name="isColumnreCommend" class="txt">
                
                    <option value="0" <?php if(isset($data) && !$data['columnrecommend']){?> selected="selected" <?php }?>>否</option>
                    <option value="1" <?php if(isset($data) && $data['columnrecommend']){?> selected="selected" <?php }?>>是</option>
                </select>
            </div>            
            <div class="add_item">
                <label>游戏名称：</label>
                <input type="text" value="<?php if(isset($data)){echo $data['gamename'];}?>" name="gamename" class="txt width500" id="gamename">
            </div>
            
            <div class="add_item">
                <label>关键字：</label>
                <input type="text" value="<?php if(isset($data)){echo $data['keywords'];}?>" name="keywords" class="txt width500" id="keywords">
            </div>
            
            <div class="add_item">
                <label>标签：</label>
                <input type="text" value="<?php if(isset($data)){echo $data['tag1'];}?>" name="tag" class="txt width500" id="tag">
                <span id="ktjbq">多个标签，使用逗号隔开</span>
            </div>
            <div class="add_item">
                <label>常用标签：</label>
                <div  id="tags" class="tags"><div><a href="javascript:moreTag()" id="moretag">点击查看更多</a></div><br/><?php if(isset($tags)){echo $tags;}?></div>

                <style type="text/css">
                    .tags{width: 1000px;height: 110px;float: left;overflow: hidden}
                    .tags_more{width: 1000px;float: left;}
                </style>
            </div>
            <div class="add_item">
                    <label>缩略图：</label>
                    <input type="hidden" value="" id="h_pic">
                    <input type="text" value="<?php if(isset($data)){echo $data['litpic'];}?>"  name="litpic" class="txt width500" id="litpic">
                    <a onclick="showupwindow('litpic')" href="javascript:;">上传</a>
                    <span style="color: silver;">列表页logo图，大小130*170</span>
            </div>
            <div class="add_item">
                    <label>试玩图片：</label>
                    <input type="text" value="<?php if(isset($data)){echo $data['newgamelitimg'];}?>"  name="newgamelitimg" class="txt width500" id="thumb">
                    <a onclick="showupwindow('thumb')" href="javascript:;">上传</a>
                    <span style="color: silver;">列表页logo图，大小240*220</span>
            </div>
            <div class="editor_box">
                <label>文章内容：</label>
                <textarea style="width: 700px; height: 690px;" id="body" name="body"><?php if(isset($data)){echo $data['body'];}?></textarea>
            </div>
            <div class="editor_box">
                <label>内容摘要：</label>
                <textarea style="width: 700px; height: 100px;" id="body1" name="description" ><?php if(isset($data)){echo $data['description'];}?></textarea>
            </div>
            <div class="editor_box">
                <label>编辑评论：</label>
                <textarea style="width: 700px; height: 100px;" id="body2" name="editor_comment" ><?php if(isset($data)){echo $data['editor_comment'];}?></textarea>
            </div>
            
            <div class="add_item">
                <label>文章来源：</label>
                <input type="text" value="<?php if(isset($data)){echo $data['source'];}else{echo '265G新游频道';}?>" name="source" class="txt width300" id="source">
            </div>
            
            <div class="add_item">
                <label>文章作者：</label>
                <input type="text" value="<?php if(isset($data)){echo $data['writer'];}else{echo $_COOKIE['nickname'];}?>" name="writer" class="txt width300" id="writer">
            </div>
            <div class="add_item">
                <label>发布时间：</label>
                <input type="text" onclick="SelectDate(this,'yyyy-MM-dd hh:mm:00')"  value="<?php if(isset($data)){echo date("Y-m-d",$data['pubdate']);}else{echo date("Y-m-d",time());}?>" name="pubdate" class="txt width300" id="pubdate">
            </div>
            
            <div class="add_item">
                <label>发布状态：</label>
                <input  type="radio" value="1" name="ismake" <?php if(isset($data) && $data['ismake']){?> checked="checked" <?php }?>/>已发布 &nbsp;&nbsp;
                <input  type="radio" value="0" name="ismake" <?php if(!isset($data) || !$data['ismake']){?> checked="checked" <?php }?>/>未发布
            </div>
            <div class="add_item">
                <label>游戏状态：</label>
                <input  type="radio" value="1" name="urltag" <?php if(isset($data) && $data['urltag']){?> checked="checked" <?php }?>/>开启 &nbsp;&nbsp;
                <input  type="radio" value="0" name="urltag" <?php if(!isset($data) || !$data['urltag']){?> checked="checked" <?php }?>/>关闭
            </div>
            <div class="btn_box">
                <input type="hidden" value="<?php if(isset($id)){echo $id;}?>"  name="id" id="article_id"/>
                <input type="hidden" value="<?php if(isset($tid)){echo $tid;}?>"  name="typeid" id="typeid"/>
                <input type="submit"  value="保存" />
                <input type="button" onclick="fanhui()" value="返回" />
            </div>
     </form>
</div>

<script type="text/javascript">
/**
*   添加文章时候判断字符串的必填与否
*/
$(function(){
    change_show_type('islist');
    change_show_type('isvideolist');
    $('#body').xheditor({upImgUrl:'!/static/xheditor/xheditor_plugins/multiupload/multiupload.html',upFlashUrl:'/static/xheditor/xheditor_plugins/multiupload/multiupload.html',upMediaUrl:'/static/xheditor/xheditor_plugins/multiupload/multiupload.html'});
    $('#body1').xheditor({upImgUrl:'!/static/xheditor/xheditor_plugins/multiupload/multiupload.html',upFlashUrl:'/static/xheditor/xheditor_plugins/multiupload/multiupload.html',upMediaUrl:'/static/xheditor/xheditor_plugins/multiupload/multiupload.html'});
    $('#body2').xheditor({upImgUrl:'!/static/xheditor/xheditor_plugins/multiupload/multiupload.html',upFlashUrl:'/static/xheditor/xheditor_plugins/multiupload/multiupload.html',upMediaUrl:'/static/xheditor/xheditor_plugins/multiupload/multiupload.html'});
});
function showupwindow(id){
    $('#h_pic').val(id);
    $('body').append('<div style="width: 349px; height: 220px; margin-left: -175px; margin-top: -110px; top: 355px;" class="xheModal" id="div_up"><div class="xheModalTitle"><span title="关闭 (Esc)" class="xheModalClose" onclick="close_up()"></span>上传文件</div><div class="xheModalContent" style="height: 191px;"><iframe frameborder="0" style="width: 100%; height: 100%;" src="/static/xheditor/xheditor_plugins/multiupload/multiupload.html?watermark=0"></iframe></div></div>');
    $('#div_up').css('top', $(document).scrollTop() + (window.screen.availHeight / 2 - 80));
}

function close_up(){
    $('#div_up').remove();
}
function fanhui(){
    history.back();
}

function check()
{
    if($('#title').val()=='')
    {
        alert('请输入标题');
        $('#title').focus();
        return false;
    }
    return true;
}
/**
*   下拉框效果
*/
function  change_show_type(id){
    $('#'+id).change(function(){
        var obj = $(this).children('option:selected');
        var val = obj.val();
        if(val != 0){
            $('#div_'+id).show();
        }else{
            $('#div_'+id).hide();
        }
    });
}

//每隔两分钟保存一次数据
setInterval('save_into_draft_box()',120000);
/**
*   数据保存草稿箱
*/
function save_into_draft_box(){
    var id          = $('#article_id').val();
    var typeid      = $('#typeid').val();
	var title       = $("#title").val();
    var shorttitle  = $("#shorttitle").val();
    var flag        = get_check_box();
    var islist      = $("#islist").val();
    var islist_pic  = $('#islist_pic').val();
    var isfirstSlideShow  = $("#isfirstSlideShow").val();
    var isColumnreCommend = $("#isColumnreCommend").val();
    var gamename    = $("#gamename").val();
    var keywords    = $("#keywords").val();
    var tag         = $("#tag").val();
    var litpic      = $("#litpic").val();
    var thumb       = $("#thumb").val();
    var body        = $('#body').val().replace(/&nbsp/g,' ');
    var description = $("#body1").val().replace(/&nbsp/g,' ');
    var comment     = $("#body2").val().replace(/&nbsp/g,' ');
    var source      = $("#source").val();
    var writer      = $("#writer").val();
    var pubdate     = $("#pubdate").val();
    var ismake      = $('input:radio[name=ismake]:checked').val();
    var urltag      = $('input:radio[name=urltag]:checked').val();

    var str = '&id='+id+'&typeid='+typeid+'&title='+title+'&shorttitle='+shorttitle+'&flag='+flag+'&islist='+islist+'&islist_pic='+islist_pic+'&isfirstSlideShow='+isfirstSlideShow+'&isColumnreCommend='+isColumnreCommend+'&gamename='+gamename;
        str += '&keywords='+keywords+'&tag='+tag+'&litpic='+litpic+'&thumb='+thumb+'&body='+body+'&description='+description+'&source='+source+'&writer='+writer+'&pubdate='+pubdate+'&ismake='+ismake+'&urltag='+urltag+'&editor_comment='+comment;
	if(title!="" && body!="")
	{
        save_data(str);
	}
}

/**
*   多选框数据
*/
function get_check_box(){
  var flag_arr= new Array();
  $('input:checkbox').each(function() {
    if ($(this).attr('checked') ==true) {
      flag_arr.push($(this).val());
    }
  }) 
  return flag_arr;
}

/**
*   保存数据
*/
function save_data(str){
	$.ajax({
		type : 'post',
		async : false,
		url  : '/index.php/admin/news/cmd_save_ajax/',
		data : str,
        dataType : 'json',
		success:function(data){
            if(data.status){
                $('#article_id').val(data.id);
                return;
            }
		}
	});	
}


</script> 
<?php $this->load->view('foot');?>